Skip to content

fix(F148): background context_briefing renders as card instead of raw JSON#395

Merged
zts212653 merged 9 commits intomainfrom
fix/briefing-render-bg
Apr 11, 2026
Merged

fix(F148): background context_briefing renders as card instead of raw JSON#395
zts212653 merged 9 commits intomainfrom
fix/briefing-render-bg

Conversation

@mindfn
Copy link
Copy Markdown
Collaborator

@mindfn mindfn commented Apr 9, 2026

Summary

  • Background thread's system_info handler was missing the context_briefing branch, causing raw JSON to render as a plain system bubble instead of a BriefingCard
  • Added context_briefing consumer to useSocket-background-system-info.ts, mirroring the existing foreground logic in useAgentMessages.ts
  • Added regression test verifying briefing card message is stored correctly (not raw JSON)

Fixes #404

Test plan

  • Red-green: pnpm exec vitest run src/hooks/__tests__/useSocket-background.test.ts -t "stores the briefing card message" — red before fix, green after
  • Full suite: pnpm exec vitest run src/hooks/__tests__/useSocket-background.test.ts — 53/53 pass
  • Manual: open a background thread with briefing, confirm no raw JSON bubble

Credits

  • 🔍 Root cause + fix: 缅因猫/砚砚 (GPT-5.4)
  • 👀 Review: 布偶猫/宪宪 (Opus 4.6)

🐾 Generated with Claude Code

…ndler

Background thread's system_info handler was missing the context_briefing
branch, causing raw JSON to render as a plain system bubble instead of
a BriefingCard. Mirrors the existing foreground logic in useAgentMessages.

[砚砚/GPT-54🐾] [宪宪/Opus-46🐾]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mindfn mindfn force-pushed the fix/briefing-render-bg branch from a9d288b to f91933a Compare April 10, 2026 05:09
@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit f91933a for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit 5ad135d for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit 35b1852 for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

} catch {
// Best-effort: don't block operation if homedir legacy files are corrupt.

P2 Badge Propagate non-corrupt homedir migration failures

The new homedir fallback swallows every error via catch {}, even though the adjacent comment says only corrupt homedir files should be ignored; this hides deterministic filesystem failures and silently skips migration. Repro (deterministic): tmp=$(mktemp -d); mkdir -p "$tmp/proj/.cat-cafe" "$tmp/home/.cat-cafe/provider-profiles.json"; HOME="$tmp/home" node scripts/install-auth-config.mjs client-auth set --project-dir "$tmp/proj" --client openai --mode oauth; echo $? (input makes provider-profiles.json a directory, so reading it raises EISDIR). Expected: non-corrupt migration failure is surfaced (non-zero exit); actual: command exits 0 and continues, so legacy homedir data is skipped without any signal.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

Review triage for the reported P2 on scripts/install-auth-config.mjs:

So this finding points to existing main-branch behavior, not a regression introduced by the context_briefing fix in #395. Treating it as non-blocking for this PR.

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit ac0e72b for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit a604b6f for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

if (body.trigger && (body.trigger as Record<string, unknown>).type === 'once') {
const result = normalizeOnceTrigger(body.trigger as Record<string, unknown>);

P1 Badge Stop anchoring once delay during preview

Deterministic repro: curl -s -X POST /api/schedule/tasks/preview with {"templateId":"reminder","trigger":{"type":"once","delayMs":60000}}, copy returned draft.trigger.fireAt, wait 70s, then curl -s -X POST /api/schedule/tasks reusing that fireAt; expected behavior is “run ~60s after registration/confirmation”, but actual behavior is immediate execution because preview already converted the relative delay to an absolute timestamp. This breaks the required preview→confirm workflow for one-shot tasks when confirmation is delayed.



P1 Badge Use trusted sender for missed-window notices

Deterministic repro: create a once task via POST /api/schedule/tasks with a forged createdBy (e.g. "spoof-cat") and a near-future fire time, stop the service before it fires, then restart after the scheduled time; expected lifecycle notification to come from a trusted system sender, but actual notification uses catId from persisted task data, enabling identity spoofing in missed-window messages. This is especially risky because createdBy is client-provided at task creation.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

Review triage for the reported P1 on packages/api/src/routes/schedule.ts:

So this finding does not describe a regression introduced by the context_briefing fix in #395. Treating it as non-blocking for this PR.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d55072398

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +104 to +106
});
}
consumed = true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve fallback when briefing payload is incomplete

This branch marks context_briefing as consumed even when no message was actually inserted (for example, if storedMessage exists but id is missing/invalid). In that case the background thread drops the event entirely instead of falling back to the existing raw system bubble path, so users get no visible signal and debugging becomes harder. Only setting consumed = true after a successful addMessageToThread would keep the previous fail-open behavior.

Useful? React with 👍 / 👎.

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 10, 2026

@codex review

Please review latest commit c2ea740 for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 11, 2026

@codex review

Please review latest commit 8ebf23f for P1/P2 only.

规则:任何 P1/P2 必须给"可执行复现":

  • 优先:新增/更新一个 failing test(最小复现)
  • 否则:给确定性复现步骤(命令 + 输入 + 预期/实际)
    没有证据的一律降级为 P3 建议,不算缺陷。

审查标准(详见 AGENTS.md "Review guidelines" section):

  • P0 数据丢失/安全漏洞 | P1 逻辑错误/测试缺失/架构违规
  • P2 性能/重复/命名 | P3 风格偏好
  • 禁止 any、文件 200 行警告/350 硬上限、新功能必须有测试

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review


P1 Badge Continue scanning candidate session files before returning null

可执行复现(最小 failing test): 在 packages/api/test/gemini-agent-service.test.js 新增用例,创建同一 sessionId 的两个 session-*.json(较新文件 messagesthoughts,较旧文件含匹配 contentthoughts),然后运行 node --test packages/api/test/gemini-agent-service.test.js --test-name-pattern "gemini session fallback"。期望:服务继续扫描并从较旧文件发出 system_info(type=thinking);实际:在首个匹配文件走到 candidates.length === 0 时直接返回,提前退出,导致 thinking 丢失。


const sessionFiles = readdirSync(chatsDir)
.filter((name) => name.startsWith('session-') && name.endsWith('.json'))
.map((name) => ({
path: join(chatsDir, name),
mtimeMs: statSync(join(chatsDir, name)).mtimeMs,

P1 Badge Prevent thinking hydration I/O errors from failing replies

可执行复现(最小 failing test): 在同一测试文件新增用例,把 HOME/.gemini/tmp/<project>/chats 目录设为不可读(chmod 000),mock 一次正常的 Gemini CLI 流(含 assistant 文本与结束事件),运行 node --test packages/api/test/gemini-agent-service.test.js --test-name-pattern "gemini unreadable chats"。期望:thinking 补全失败应被忽略,仍返回正常文本与 done;实际:这里的目录扫描抛出 EACCES 后会冒泡到 invoke 外层 catch,把一次成功回答转成 error 事件。

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn
Copy link
Copy Markdown
Collaborator Author

mindfn commented Apr 11, 2026

Review triage for the reported P1s on packages/api/src/domains/cats/services/agents/providers/GeminiAgentService.ts:

  • This file is not part of PR fix(F148): background context_briefing renders as card instead of raw JSON #395's diff.
  • gh pr diff 395 --name-only still lists only:
    • packages/web/src/hooks/useSocket-background-system-info.ts
    • packages/web/src/hooks/__tests__/useSocket-background.test.ts
  • git diff origin/main...origin/fix/briefing-render-bg -- packages/api/src/domains/cats/services/agents/providers/GeminiAgentService.ts is empty.
  • The reviewer-cited code at GeminiAgentService.ts:106-110 and :126 is identical on origin/main and on the latest PR head 8ebf23fb.

So these findings describe existing main-branch behavior brought in by the merge-from-main commit, not a regression introduced by the context_briefing fix in #395. Treating them as non-blocking for this PR.

@zts212653 zts212653 merged commit 4e18a19 into main Apr 11, 2026
5 checks passed
@mindfn mindfn deleted the fix/briefing-render-bg branch April 11, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: background thread context_briefing renders as raw JSON instead of BriefingCard

2 participants